<?php
require_once(dirname(__FILE__)."/../../libs/dbclass/dbconnect.php");
require_once(dirname(__FILE__)."/../../libs/string/libstr.php");
$mc= new libstr();

class member{
	
//获取会员列表 string 代表选择项
	function memberlist($string="*",$userid="",$userno="",$username="",$sex="",$email="",$shouji="",$address="",$isshow="",$starttime="",$endtime="",$order="",$sj="desc",$pagesize=10,$page=1)
	{
		global $mc,$db;
		
		
		$_string="*";
		if($string!="")
		{
			$_string=$string;
		}		
		$_userid="";
		if($userid!="")
		{
			$_userid=" and userid like '%".trim($userid)."%' ";
		}	
		$_username="";
		if($username!="")
		{
			$_username=" and username like '%".trim($username)."%' ";
		}
		$_sex="";
		if($sex!="")
		{
			$_sex=" and sex=".$sex." ";
		}
		$_email="";
		if($email!="")
		{
			$_email=" and email like '%".trim($email)."%' ";
		}
	
		$_address="";
		if($address!="")
		{
			$_address=" and dizhi like '%".trim($address)."%' ";
		}

		$_isshow="isshow>=0";	
		if($isshow!="")
		{				
			$_isshow=" isshow=".$isshow." ";
		}
		
		$regtime="";
	if($starttime!=""){

		$_regtime.=" and regtime >= ".strtotime($starttime);
	}
	if($endtime!=""){
	
		$_regtime.=" and regtime <= ".strtotime($endtime);

	}
		$_where=$_isshow.$_userid.$_username.$_creattime.$_sex.$_email.$_address.$_regtime;
		
		$_tb="member_content";
		$_order="";
		if($order!="")
		{
			$_order=" order by ".$order." ".$sj." ";	
		}
				
		$_pagesize=$pagesize;
		$_page=$page;
					
		$totalcount_xiaoquan=$db->getcount("id",$_tb,$_where);		
		$getrs=$db->pagerds($_string,$_tb,$_where,$_order,$totalcount_xiaoquan,$_pagesize,$_page);
		$i=0;
		if($totalcount_xiaoquan>0){
		foreach($getrs as $v)
		{
			$getrs[$i]=$v;
			$getrs[$i]["totalcount"]=$totalcount_xiaoquan;
			$i=$i+1;
		}
		}
		return $getrs;
		
	}
//获得会员详细
function getmembershow($usrno){
	global $mc,$db;
	$mbshow=array();
	if($mc->Ismp($usrno)!=""){
	$mbshow=$db->dvstr("select * from member_content where userno='".$usrno."' limit 1");	
	}
	return $mbshow;
}

//添加会员
function member_add($userid,$password,$username="",$pic="",$sex="",$email="",$phone="",$tel="",$address="",$shengri=0,$qq="",$web="",$rootid="0,1,",$isshow=0,$adduserno=0)
	{
		global $mc,$db;
		$memberadd=array();
		if($userid==""){return "userid is null"; }
		$myts=$db->dvstr("select count(*) as t from member_content where userid='".$userid."'");
		if($myts["t"] >0)
		{
			return "userid is exist ";
		}
		if($password==""){return "password is null"; }
		$randval = substr(rand(), 0,3);
		$db->cmd("update createuserno set userno=userno+1");
		$getno= $db->dvstr("select * from createuserno");
		$userno=$getno["userno"].$randval;
		
		$memberadd["userid"]=$userid;		
		$memberadd["password"]=strtoupper(md5(strtolower(trim($password))));
		$memberadd["userno"]=$userno;
		$memberadd["rootid"]=$rootid;//"0,1,形式，代表用户身份"
		$memberadd["adduserno"]=$adduserno;//添加人
		$memberadd["username"]=$username;
		$memberadd["sex"]=$sex;
		$memberadd["email"]=$email;
		$memberadd["phone"]=$phone;
		$memberadd["tel"]=$tel;
		$memberadd["address"]=$address;
		$memberadd["shengri"]=$shengri;
		$memberadd["qq"]=$qq;
		$memberadd["web"]=$web;	
		$memberadd["regtime"]= $_SERVER["REQUEST_TIME"];
		$memberadd["pic"]=$pic;
		$memberadd["isshow"]=$isshow;
		$memberadd["regip"]=$mc->getip();
		$table="member_content";
		$db->add_data($table,$memberadd);
		return "add is ok";
	}
//更新会员信息
function member_edit($userno,$username="",$rootid="0,4,5,",$sex="",$email="",$phone="",$tel="",$address="",$shengri=0,$qq="",$web=""){
        global $db;
        if($userno==""){
        	return "userno is null";
        }
		$memberadd["username"]=$username;
		$memberadd["rootid"]=$rootid;
		$memberadd["sex"]=$sex;
		$memberadd["email"]=$email;
		$memberadd["phone"]=$phone;
		$memberadd["tel"]=$tel;
		$memberadd["address"]=$address;
		$memberadd["shengri"]=$shengri;
		$memberadd["qq"]=$qq;
		$memberadd["web"]=$web;	
		$memberadd["updatetime"]= $_SERVER["REQUEST_TIME"];
		$table="member_content";
		$db->update_data($table,$memberadd," userno=".$userno);
		return "update is ok";
	
}
//删除多个会员
function member_del($arr){
	global $mc,$db;
	$str=sprintf("%s",implode(",",$arr));
	$db->cmd("delete from member_content where id in(".$str.")");
	return true;	
}
//更新多个会员状态
function updateisshow($arr,$isshow=1){
	global $db;
	$str=sprintf("%s",implode(",",$arr));
	$db->cmd("update member_content set isshow=".$isshow."  where id in(".$str.")");
	return true;
}
//更新1个会员状态
function updateoneisshow($id){
	global $db;

	$db->cmd("update member_content set isshow=".$isshow."  where id=".$id);
	return true;
}
	//判断是否有子集
function myck($id)
{

	global $db;
	$rs1=$db->ds("select * from member_class where pid='".trim($id)."'");
	if(count($rs1)>0){
		return true;
	}else{
		return false;
	}
}

//转化级别类名
function getclassname($rootid){
	global $mc,$db;
	$cc=$db->dvstr("select * from member_class where rootid='".$rootid."'");
	return $cc["classname"];
}	

//获取rootid
function getrootid($id){
	global $mc,$db;
	$cc=$db->dvstr("select * from member_class where ID='".$id."'");
	return $cc["rootid"];
}
	

//用户状态
function showzhuangtai($str)
{
	if($str=="-1")
	{
		return "不通过";
	}
	if($str=="0")
	{
		return "未审核";
	}
	if($str=="1")
	{
		return "已审核";
	}
	if($str=="-2")
	{
		return "回收站";
	}
	return '--';
}
}
//$mb=new member();
//$mbs=$mb->member_add("tyu","123");
//print_r($mbs);
?>